package com.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * Created by Administrator on 2018/5/29.
 */
public class FutureDemo1 {

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        Callable<Chuju> onlineShopping = new Callable<Chuju>() {
            @Override
            public Chuju call() throws Exception {
                System.out.println("第一步：下单");
                System.out.println("第一步：等待送货");
                Thread.currentThread().sleep(5000);
                System.out.println("第一步：厨具送到");
                return new Chuju();
            }
        };
        FutureTask<Chuju> task = new FutureTask<Chuju>(onlineShopping);
        new Thread(task).start();
        //2、购买食材
        try {
            Thread.currentThread().sleep(2000);
            Shicai shicai = new Shicai();
            System.out.println("第二步：食材到位");
            //联系快递员，询问是否到货
            if(!task.isDone()){
                System.out.println("第三步：厨具还没到，心情好就等着（心情不好就调用cancel方法取消订单）");
            }
            Chuju chuju = task.get();
            System.out.println("第三步：厨具到位，开始做饭");
            cook(chuju,shicai);
            System.out.println("总共用时" + (System.currentTimeMillis() - startTime) + "ms");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    static void cook(Chuju chuju,Shicai shicai){

    }

    static class Chuju{

    }

    static class Shicai{

    }
}
